package com.javasm.controller.goods;


import com.javasm.common.http.AxiosResult;
import com.javasm.common.page.PageResult;
import com.javasm.common.valid.addGroup;
import com.javasm.controller.base.BaseController;
import com.javasm.domin.criteria.goods.GiftsToGoodsCriteria;
import com.javasm.domin.criteria.goods.GoodsAdjustCriteria;
import com.javasm.domin.entity.goods.GiftsToGoods;
import com.javasm.domin.entity.goods.GoodsAdjust;
import com.javasm.domin.vo.goods.GiftsToGoodsVo;
import com.javasm.domin.vo.goods.GoodsAdjustVo;
import com.javasm.service.goods.IGiftsToGoodsService;
import com.javasm.service.goods.IGoodsToGiftsService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author whl
 * @since 2022-01-16
 */
@RestController
@RequestMapping("gifts-to-goods")
@RequiredArgsConstructor
public class GiftsToGoodsController extends BaseController {

    private final IGiftsToGoodsService iGiftsToGoodsService;
    /**
     * 分页条件查询
     */
    @GetMapping
    public AxiosResult<PageResult<GiftsToGoodsVo>> list(GiftsToGoodsCriteria giftsToGoodsCriteria) {
        PageResult<GiftsToGoodsVo> list = iGiftsToGoodsService.searchPage(giftsToGoodsCriteria);
        return AxiosResult.success(list);
    }

    /**
     * 分页条件查询
     */
    @GetMapping("findByApproveStatus")
    public AxiosResult<PageResult<GiftsToGoodsVo>> list1(GiftsToGoodsCriteria giftsToGoodsCriteria) {
        PageResult<GiftsToGoodsVo> list = iGiftsToGoodsService.searchPage1(giftsToGoodsCriteria);
        return AxiosResult.success(list);
    }


    /**
     * 添加
     */
    @PostMapping
    public AxiosResult<Void> add(@Validated(addGroup.class) @RequestBody GiftsToGoods giftsToGoods ) {
        return toAxios(iGiftsToGoodsService.save(giftsToGoods));
    }



    /**
     * 根据id查询
     */
    @GetMapping("{id}")
    public AxiosResult<GiftsToGoods> findById(@PathVariable Long id) {
        GiftsToGoods byId = iGiftsToGoodsService.getById(id);
        return AxiosResult.success(byId);
    }


    /**
     * 修改
     */
    @PutMapping
    public AxiosResult<Void> update(@RequestBody GiftsToGoods giftsToGoods ) {
        return toAxios(iGiftsToGoodsService.update(giftsToGoods));
    }

    /**
     * 删除
     */
    @DeleteMapping("{id}")
    public AxiosResult<Void> delete(@PathVariable Long id) {
        return toAxios(iGiftsToGoodsService.deleteById(id));
    }


    /**
     * 批量删除
     */
    @DeleteMapping("batch/{ids}")
    public AxiosResult<Void> batch(@PathVariable List<Long> ids) {
        return toAxios(iGiftsToGoodsService.batchDeleteByIds(ids));
    }
}
